/*--------------------------------------------------------------------------------*/
#ifndef __DEBUG__
#define __DEBUG__
/*--------------------------------------------------------------------------------*/
class TEXT;
#include "primitives.h"
#include <iostream>
#include <GL/gl.h>
#include <cassert>
using namespace std;
/*--------------------------------------------------------------------------------*/
#ifdef _DEBUG
	#define DEBUG_Log( x ) 							DEBUG::Log( x )
	#define DEBUG_LogLine( x ) 							DEBUG::LogLine( x )
	#define DEBUG_CheckOpenGL( x ) 					DEBUG::CheckOpenGL( x )
	#define DEBUG_Require( _CONDITION_ )			assert( _CONDITION_ )
    #define DEBUG_Break( x )						DEBUG::Log( x ); assert( 11 < 7 )
#else
    #define DEBUG_Log( x )
	#define DEBUG_LogLine( x )
	#define DEBUG_CheckOpenGL( x )
	#define DEBUG_Require( _CONDITION_ )
	#define DEBUG_Break( x )
#endif
/*--------------------------------------------------------------------------------*/
#ifdef _DEBUG
class DEBUG
{
	// -- PUBLIC

public:

    // .. FUNCTIONS

    static VOID LogLine( const TEXT & message );

    template< typename _CLASS_ >
    static VOID LogLine( const _CLASS_ & message )
    {
    	cout << message << endl;
    }

    static VOID Log( const TEXT & message );

    template< typename _CLASS_ >
    static VOID Log( const _CLASS_ & message )
    {
    	cout << message;
    }

    static VOID CheckOpenGL()
    {
    	GLuint
			error;

    	error = glGetError();

    	if( !error )
    	{
    		return;
    	}

    	switch( error )
    	{
			case GL_INVALID_ENUM:
			{
				DEBUG_LogLine( "OpenGL error : Invalid enum" );
			}
			break;
			case GL_INVALID_VALUE:
			{
				DEBUG_LogLine( "OpenGL error : Invalid value" );
			}
			break;
			case GL_INVALID_OPERATION:
			{
				DEBUG_LogLine( "OpenGL error : Invalid operation" );
			}
			break;
			case GL_STACK_OVERFLOW:
			{
				DEBUG_LogLine( "OpenGL error : Stack overflow" );
			}
			break;
			case GL_STACK_UNDERFLOW:
			{
				DEBUG_LogLine( "OpenGL error : Stack underflow" );
			}
			break;
			case GL_OUT_OF_MEMORY:
			{
				DEBUG_Log( "OpenGL error : Out of memory" );
			}
			break;
    	}

    	assert( error == 0 );
    }
};
#endif
/*--------------------------------------------------------------------------------*/
#endif
